//
//  ScannerViewController.m
//  AffectionBee
//
//  Created by 李通 on 16/8/18.
//  Copyright © 2016年 chivalrous. All rights reserved.
//

#import "ScannerViewController.h"
#import <AVFoundation/AVFoundation.h>
#import <QuartzCore/QuartzCore.h>

@interface ScannerViewController ()

@property (nonatomic,strong) AVCaptureInput *input;

@property (nonatomic,strong) AVCaptureMetadataOutput *output;

@property (nonatomic,strong) AVCaptureSession *session;

@property (nonatomic,weak) UIImageView *lineImageView;

@property (nonatomic,weak) UIImageView *areaImageView;

@end

@implementation ScannerViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor whiteColor];
    [self setupUI];
    
    [self startAnimation];

}

- (void)setupUI {
    
    UIImageView *areaImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 200, 200)];
    areaImageView.center = self.view.center;
    areaImageView.backgroundColor = [UIColor darkGrayColor];
    self.areaImageView = areaImageView;
    [self.view addSubview:areaImageView];

    
    UIImageView *lineImageView = [[UIImageView alloc]init];
    lineImageView.image = [UIImage imageNamed:@"yellowlight"];
    self.lineImageView = lineImageView;
    [self.areaImageView addSubview:lineImageView];
    [lineImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.areaImageView);
        make.centerX.equalTo(self.areaImageView);
        make.width.equalTo(@170);
        make.height.equalTo(@5);
    }];
}

- (void)startAnimation {
    
    CABasicAnimation *anim = [CABasicAnimation animationWithKeyPath:@"position.y"];
    anim.fromValue = @(self.lineImageView.frame.origin.y);
    anim.toValue = @(200);
    anim.duration = 1.5;
    anim.repeatCount = MAXFLOAT;
    [self.lineImageView.layer addAnimation:anim forKey:nil];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
}


@end
